script_enemy_main{

let effect1=0;
let dial=[];
let dialscale=0;
let dialangle=0;   //45=spring 135=summer 225=autumn 315=winter 
let dialcolor=128;
let dialspin=0;

let bgscroll=[0,225,450,675];
let bgpos=[rand(-200,0),rand(0,200),rand(-200,0),rand(0,200)];
let bgsize=[rand(0.6,1),rand(0.6,1),rand(0.6,1),rand(0.6,1)];

let turn=0;
let anglez=rand_int(0,360);
let radius=0;
let flowerx=0;
let flowery=0;
let shotdelay1=0;
let shotdelay2=30;
let shot=0;
let anglex=0;
let color=0;
let phase=rand_int(0,1);
let shotsound=0;

let resetwait=0;
let size1=52;
let size2=size1+36;

let shot1=0;
let bullet1=[];
let timer1=[];

let shot2=0;
let bullet2=[];
let timer2=[];
let color2=[];

let character="Ayano";
let cutin=character;
let spellcards=1;
let spellcardnumber=12;
let dispelled=0;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=-180;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEmagics1=("\script\SoundEffects\magics1.wav");
let SEshots5=("\script\SoundEffects\shots5.wav");
let SEshots7=("\script\SoundEffects\shots7.wav");
let SEcharge1=("\script\SoundEffects\charge1.wav");

let EFdial=("\script\Images\BackgroundLayers\Ayano1.png");
let SEdialturn1=("script\SoundEffects\stone1.wav");
let SEdialturn2=("script\SoundEffects\stone2.wav");

let BG1=("\script\Images\BackgroundLayers\Ayano2.png");
let BG2=("\script\Images\BackgroundLayers\Ayano3.png");
let BG3=("\script\Images\BackgroundLayers\Ayano4.png");
let GRboss=("\script\Images\CharacterSprites\Ayano.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsAyano1.txt");

	LoadGraphic("\script\Images\BackgroundLayers\Ayano1.png");
	LoadSE("script\SoundEffects\stone1.wav");
	LoadSE("script\SoundEffects\stone2.wav");

	LoadSE("\script\SoundEffects\magics1.wav");
	LoadSE("\script\SoundEffects\shots7.wav");
	LoadSE("\script\SoundEffects\charge1.wav");

	LoadGraphic("\script\Images\CharacterSprites\Ayano.png");
	LoadGraphic("\script\Images\BackgroundLayers\Ayano2.png");
	LoadGraphic("\script\Images\BackgroundLayers\Ayano3.png");
	LoadGraphic("\script\Images\BackgroundLayers\Ayano4.png");

	SetScore(150000);
	SetLife(350);
	SetTimer(50);
	SetInvincibility(180);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+100,50);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(32,32,32,32);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=7; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("Summer [Yellow Empress] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);

if(time%200==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+60,miny+120),1.5);
	}
}


if(frame==-180){
let hpos=0;
	loop(4){
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,cx,miny+150);
	ObjEffect_SetAngle(effect1,0,0,0);
	ObjEffect_SetScale(effect1,0,0);
	ObjEffect_SetLayer(effect1,1); ObjEffect_SetTexture(effect1,EFdial); ObjEffect_SetRenderState(effect1,ALPHA);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-150,-150); ObjEffect_SetVertexUV(effect1,0,0+hpos,0);
	ObjEffect_SetVertexXY(effect1,1,150,-150); ObjEffect_SetVertexUV(effect1,1,300+hpos,0);
	ObjEffect_SetVertexXY(effect1,2,-150,150); ObjEffect_SetVertexUV(effect1,2,0+hpos,300);
	ObjEffect_SetVertexXY(effect1,3,150,150); ObjEffect_SetVertexUV(effect1,3,300+hpos,300);
	ObjEffect_SetVertexColor(effect1,0,255,255,255,255); ObjEffect_SetVertexColor(effect1,1,255,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,255,255,255,255); ObjEffect_SetVertexColor(effect1,3,255,255,255,255);
	dial=dial~[effect1];
	hpos+=300;
	}
dialspin=135;
}

if(frame>=-180){
let i=0;
	loop(4){
	ObjEffect_SetScale(dial[i],dialscale,dialscale);
	i++;
	}

if(dialscale<1){ dialscale+=0.05; if(dialscale>=1){ PlaySE(SEdialturn1); } }
if(dialspin>0 && dialscale>=1){ dialangle+=1; dialspin--; }
if(dialspin<0 && dialscale>=1){ dialangle-=1; dialspin++; }
if(dialspin==0 && dialcolor==130){ PlaySE(SEdialturn2); }

if(dialspin==0 && dialcolor<255){ dialcolor+=2; }
ObjEffect_SetVertexColor(dial[2],0,dialcolor,255,255,255); ObjEffect_SetVertexColor(dial[2],1,dialcolor,255,255,255);
ObjEffect_SetVertexColor(dial[2],2,dialcolor,255,255,255); ObjEffect_SetVertexColor(dial[2],3,dialcolor,255,255,255);

ObjEffect_SetAngle(dial[1],0,0,dialangle);
ObjEffect_SetAngle(dial[2],0,0,dialangle);
ObjEffect_SetAngle(dial[3],0,0,dialangle);
}

if(frame==-30){ 
	SetColor(255,160,200);
	Concentration01(90);
	SetColor(255,255,255);
}


if((OnBomb==false && GetEnemyShotCount<=0 && resetwait<=0 && frame>100) || frame>=460){ frame=0; }

if(frame==10 && time>=180){ SetColor(255,160,200); Concentration01(90); SetColor(255,255,255); PlaySE(SEcharge1); }

if(frame==100){
	flowerx=cx+rand(-80,80);
	flowery=miny+rand(120,150);
	turn=0;
	anglez=rand_int(0,360);
	radius=0;
	shotdelay1=0;
	shotdelay2=30;
	shot=0;
	anglex=0;
	color=0;
	phase++;
}

if(frame>=100 && shot<size1){
	loop(5){
	let radius=0.05^0.5*turn;
	let anglex=0;
		if(phase%2==0){ anglex=(turn+anglez)*137.5; }
		if(phase%2!=0){ anglex=(-turn+anglez)*137.5; }
	SetShotColor(100,100,100);
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,flowerx+radius*cos(anglex),flowery+radius*sin(anglex));
	Obj_SetAngle(shot1,anglex);
	ObjShot_SetGraphic(shot1,3);
	ObjShot_SetDelay(shot1,15);
	ObjShot_SetBombResist(shot1,true);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=140+shotdelay1;
	SetShotColor(255,255,255);
	turn+=1;
	anglex+=360/5;
	}
anglex+=1;
shot++;
shotdelay1+=3;
if(time%10==0){ PlaySE(SEshots5); }
}


if(shot>=size1 && shot<size2){
SetShotColor(255,200+color,200+color);
	loop(5){
	let radius=0.05^0.5*turn;
	let anglex=0;
		if(phase%2==0){ anglex=(turn+anglez)*137.5; }
		if(phase%2!=0){ anglex=(-turn+anglez)*137.5; }
	shot2=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot2,flowerx+radius*cos(anglex),flowery+radius*sin(anglex));
	Obj_SetAngle(shot2,anglex);
	ObjShot_SetGraphic(shot2,15);
	ObjShot_SetDelay(shot2,15);
	ObjShot_SetBombResist(shot2,true);
	bullet2=bullet2~[shot2];
	timer2=timer2~[shot2];
	timer2[length(bullet2)-1]=140+shotdelay1+shotdelay2;
	color2=color2~[shot2];
	color2[length(bullet2)-1]=color;
	turn+=1;
	anglex+=360/5;
	}
anglex+=1;
shot++;
shotdelay2+=3;
color+=55/size2;
SetShotColor(255,255,255);
if(time%10==0){ PlaySE(SEmagics1); }
}


let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i);
	i--;
	}
	else{
	if(timer1[i]<=0){
	SetShotColor(100,100,100);
	let angle=Obj_GetAngle(bullet1[i])-4;
		loop(2){
		CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,angle+rand(-3,3),rand(0.03,0.04),rand(2.5,3),3,0);
		angle+=8;
		}
	if(shotsound<=0){ PlaySE(SEshots5); shotsound=5; }
	SetShotColor(255,255,255);
	Obj_Delete(bullet1[i]);
	}
	if(OnBomb){ ObjShot_SetBombResist(bullet1[i],false); }
	else{ ObjShot_SetBombResist(bullet1[i],true); }
	timer1[i]=timer1[i]-1;
	}
i++;
}

let i=0;
while(i<length(bullet2)){
	if(Obj_BeDeleted(bullet2[i])){
	bullet2=erase(bullet2,i); timer2=erase(timer2,i); color2=erase(color2,i);
	i--;
	}
	else{
	if(timer2[i]<=0){
	SetShotColor(255,200+color2[i],200+color2[i]);
	let shota=0;
		CreateShotA(shota,Obj_GetX(bullet2[i]),Obj_GetY(bullet2[i]),0);
		SetShotDataA(shota,0,1,Obj_GetAngle(bullet2[i]),1.2,0.02,1.7,15);
		SetShotDataA(shota,50,NULL,NULL,0,0.02,1.7,15);
		FireShot(shota);
		CreateShotA(shota,Obj_GetX(bullet2[i]),Obj_GetY(bullet2[i]),0);
		SetShotDataA(shota,0,1,Obj_GetAngle(bullet2[i]),-1.2,0.02,1.7,15);
		SetShotDataA(shota,50,NULL,NULL,0,0.02,1.7,15);
		FireShot(shota);
	if(shotsound<=0){ PlaySE(SEshots7); shotsound=5; }
	SetShotColor(255,255,255);
	Obj_Delete(bullet2[i]);
	}
	if(OnBomb){ ObjShot_SetBombResist(bullet2[i],false); }
	else{ ObjShot_SetBombResist(bullet2[i],true); }
	timer2[i]=timer2[i]-1;
	}
i++;
}

if(shotsound>0){ shotsound--; }



time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<255){ bgfade+=5; }

	SetGraphicRect(0,0,300,300);
	SetTexture(BG3);
	SetAlpha(255);
	SetColor(bgfade/2,bgfade/2,bgfade/2);
	SetGraphicScale(2,2);
	SetGraphicAngle(0,0,-time/7);
	DrawGraphic(cx,cy);

	SetGraphicRect(0,0,400,400);
	SetTexture(BG1);
	SetAlpha(255);
	SetColor(bgfade*0.6,bgfade*0.6,bgfade*0.6);
	SetGraphicScale(1.5,1.5);
	SetGraphicAngle(0,0,time/10);
	DrawGraphic(cx,cy);

	SetGraphicRect(0,0,400,400);
	SetTexture(BG2);
	SetAlpha(255);
	SetColor(bgfade*0.8,bgfade*0.8,bgfade*0.8);
	SetRenderState(ALPHA);
	let i=0;
		loop(4){
		SetGraphicScale(bgsize[i],bgsize[i]);
			if(i%2==0){ SetGraphicAngle(0,0,time); }
			if(i%2!=0){ SetGraphicAngle(0,0,-time);}
		DrawGraphic(cx+bgpos[i],bgscroll[i]);
		bgscroll[i]=bgscroll[i]+1.5;
		if(bgscroll[i]>700){
			bgscroll[i]=-200;
			if(i%2==0){ bgpos[i]=rand(-200,0); SetGraphicAngle(0,0,time); }
			if(i%2!=0){ bgpos[i]=rand(0,200); SetGraphicAngle(0,0,-time);}
			bgsize[i]=rand(0.6,1);
			}
		
		i++;
		}
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}